/*
 * @(#)SSEArrayList.java 1.0 2005-2-28
 * Copyright 2005 VandaGroup, Inc. All rights reserved.
 */
package com.vanda.util;
import java.util.ArrayList;
import java.util.Collection;
/*******
 * 类说明:
 * 供ActionForm中使用，以避免OutOfIndexException
 * 注意：不要在其他方面使用VandaArrayList!
 * <P>@author wkf3915
 * <P>@version 1.0 2005-2-28
 */
public class VandaArrayList extends ArrayList {
	Class clazz; // 容器内保存的类
	/**
	 * 私有构造函数，保证外界无法直接实例化
	 */
	private VandaArrayList() {
	}
	
	public VandaArrayList(Class clazz) {
		this.clazz = clazz;
	}
	
	public VandaArrayList(Collection ct){
		if(ct != null || ct.size() > 0){
			this.clazz = ct.iterator().next().getClass();
			super.addAll(ct);
		}
	}
	
	/**
	 * save the updates of customer types.
	 */
	public Object get(int index) {
		try {
			if (super.size() < index + 1) {
				int cnt = index + 1 - super.size();
				for (int i = 0; i < cnt; i++) {
					super.add(clazz.newInstance());
				}
			}
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return super.get(index);
	}
}
